//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import CampHouseOrderBox from '../../views/mall/CampHouseOrderBox.vue'
import CampsiteLeaseBox from '../../views/mall/CampsiteLeaseBox.vue'
let extension = {
    components: {//动态扩充组件或组件路径
        //表单header、content、footer对应位置扩充的组件
        gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
        gridBody: CampHouseOrderBox,
        gridFooter: CampsiteLeaseBox,
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        modelHeader: '',
        modelBody: '',
        modelFooter: ''
    },
    buttons: {
        view: [
            {
                name: "手工下单",
                icon: '',
                value: 'PlaceOrder',
                class: '',
                type: 'error',
                index: 1,//显示的位置
                onClick: function () {
                    this.$refs.gridBody.openXD()
                }
            },
            // {
            //     name: "押金",
            //     icon: '',
            //     value: 'RentingOut',
            //     class: '',
            //     type: 'error',
            //     index: 2,//显示的位置
            //     onClick: function () {
            //         let selection = this.$refs.table.$refs.table.selection
            //         if (selection.length < 1) {
            //             this.$Message.error('请选择一行数据')
            //         } else {
            //             this.$refs.gridBody.openYJ(selection, 0)
            //         }
            //     }
            // }
        ], box: [], detail: []
    },//扩展的按钮
    methods: {//事件扩展
        onInit () {
            this.$store.getters.data().viewPageTest = this;
            this.searchFormFileds.createDate = [this.getStartDate(), this.getEndDate()]
            let parmas = {
                page: 1,
                rows: 30,
                sort: "modifyDate",
                order: "id",
                wheres: `[]`,
            };
            this.http
                .post("/api/CampHouseType/getPageData", parmas)
                .then((res) => {
                    this.columns.forEach(i => {
                        if (i.field == 'houseType') {
                            i.bind.data = res.rows.map(j => {
                                return {
                                    key: j.id,
                                    value: j.name
                                }
                            })
                        }
                    })
                });
            this.columns.push({
                field: 'status',
                title: '操作',
                fixed: 'right',
                width: 170,
                render: (h, { row, column, index }) => {
                    return [
                        h(
                            "el-button", {
                            props: {
                                type: 'text', size: 'mini',
                                disabled: row.isUse == 0 ? false : true
                            },
                            on: {
                                click: (e) => {
                                    this.$refs.gridBody.openFF(row)
                                }
                            }
                        }, '分房'),
                        h(
                            "el-button", {
                            props: {
                                type: 'text', size: 'mini',
                                disabled: row.isUse == 0 ? false : true
                            },
                            style: {
                                "margin-left": "10px"
                            },
                            on: {
                                click: (e) => {
                                    if (row.isReserve == 1) {
                                        if (row.isHouseDeposit == 0 || row.isHouseDeposit == null) {
                                            this.$refs.gridBody.openYJ([row], 1)
                                        } else {
                                            let parmas = {
                                                page: 1,
                                                rows: 30,
                                                sort: "modifyDate",
                                                order: "id",
                                                wheres: `[{\"name\":\"orderNumber\",\"value\":\"${row.orderNumber}\",\"displayType\":\"=\"}]`,
                                            };
                                            this.http
                                                .post("/api/CampsiteHouseItem/getPageData", parmas)
                                                .then((res) => {
                                                    if (res.rows.length == 1) {
                                                        let parma = {
                                                            id: res.rows[0].chid,
                                                            type: 1,
                                                            chId: res.rows[0].chid,
                                                            orderNumber: row.parentNumber,
                                                            childOrderNumber: [row.orderNumber],
                                                        };
                                                        this.http.post("/api/CampHouseOrder/OrderWriteOff", parma).then((res) => {
                                                            if (res.status) {
                                                                this.$Message.success("核销成功");
                                                                this.refresh();
                                                            } else {
                                                                this.$Message.error(res.message);
                                                            }
                                                        });
                                                    }
                                                });
                                        }
                                    } else {
                                        this.$Message.error('请先分房');
                                    }
                                }
                            }
                        }, '核销'),
                        h(
                            "el-button", {
                            props: {
                                type: 'text', size: 'mini',
                                disabled: row.isUse == 2 ? false : true
                            },
                            on: {
                                click: (e) => {
                                    this.$refs.gridFooter.billPrintClick(row)
                                }
                            }
                        }, '打印'),
                        h(
                            "el-button", {
                            props: {
                                type: 'text', size: 'mini',
                                disabled: row.status == 1 ? true : false
                            },
                            on: {
                                click: (e) => {
                                    console.log(row);
                                    this.$refs.gridBody.GetMerchantPayInfo(row)
                                }
                            }
                        }, row.reservationType == 1 ? '支付' : ''),
                    ]
                }
            })
        },
        rowClick ({ row, column, event }) {
            this.$refs.table.$refs.table.toggleRowSelection(row);
            return true;
        },
        searchAfter (result) { //查询ViewGird表数据后param查询参数,result回返查询的结果
            result.forEach(i => {
                i.DISABLED = i.isUse == 1 ? true : false
            })
            return true;
        },
        getStartDate (dates) {
            var dd = new Date();
            var n = dates || 0;
            dd.setDate(dd.getDate() + n);
            var y = dd.getFullYear();
            var m = dd.getMonth() + 1;
            var d = dd.getDate();
            m = m < 10 ? "0" + m : m;
            d = d < 10 ? "0" + d : d;
            var day = y + "-" + m + "-" + d + " 00:00:00";
            return day;
        },
        getEndDate (dates) {
            var dd = new Date();
            var n = dates || 0;
            dd.setDate(dd.getDate() + n);
            var y = dd.getFullYear();
            var m = dd.getMonth() + 1;
            var d = dd.getDate();
            m = m < 10 ? "0" + m : m;
            d = d < 10 ? "0" + d : d;
            var day = y + "-" + m + "-" + d + " 23:59:59";
            return day;
        }
    }
};
export default extension;